<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>

<body>
    <div id="app">
        <div v-for="(item, index) in arr">
            {{index}} ---> {{item}}
        </div>

        <div v-for="(item, index) in jarr">
            {{index}} ---> {{item.name}} ---> {{item.age}}
        </div>
        <!-- v:值，k:键，i:索引 -->
        <div v-for="(v, k, i) in user">
            {{k}} ---> {{v}} --->{{i}}
        </div>
        <!-- 这儿从1开始 -->
        <div v-for="count in 10">
            这是第 {{count}} 数字
        </div>

        <!-- 2.2.0后， 在组件中 for循环的key必须使用 -->
        <label for="">name
            <input type="text" name="name" id="" v-model:value="name">
        </label>
        <label for="">age
            <input type="text" name="age" id="" v-model:value="age">
        </label>
        <label for="">
            <input type="button" value="添加" @click="add">
        </label>
        <!-- 不能使用索引作为key，key必须是string 或者 int型 -->
        <div v-for="(item, index) in jarr" :key="item.id">
            <input type="checkbox" name="" id=""> {{index}} ---> {{item.name}} ---> {{item.age}}
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                jarr: [{
                    id: 1,
                    name: "Alice",
                    age: 52,
                }, {
                    id: 2,
                    name: "Bob",
                    age: 78,
                }, {
                    id: 3,
                    name: "Frank",
                    age: 52,
                }],
                user: {
                    id: 4,
                    name: "Alice",
                    age: 51,
                    password: 5555,
                },
                name: "",
                age: 0,
            },
            methods: {
                add() {
                    // this.jarr.push({
                    //     name: this.name,
                    //     age: this.age,
                    // })
                    this.jarr.unshift({
                        name: this.name,
                        age: this.age,
                    })
                }
            }
        });
    </script>
</body>

</html>